package com.diandian.backend.member.controller;

import com.alibaba.fastjson.JSON;
import com.diandian.backend.member.dto.DouyinLifeMemberInfoAddParamDTO;
import com.diandian.backend.member.dto.MemberDouyinLifeMemberInfoPageParamDTO;
import com.diandian.backend.member.service.DouyinLifeMemberInfoService;
import com.diandian.base.boot.starter.response.BaseResult;
import com.diandian.backend.member.param.*;
import com.diandian.base.boot.starter.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 线上抖音本地生活会员信息表
 *
 * @author zyz diandian@qq.com
 * @since 1.0.0 2025-07-09
 */
@RestController
@RequestMapping("/douyin/life/member/info")
public class DouyinLifeMemberInfoController {

    private static final Logger logger = LoggerFactory.getLogger(DouyinLifeMemberInfoController.class);

    @Autowired
    private DouyinLifeMemberInfoService douyinLifeMemberInfoService;

    @PostMapping("/page")
    public BaseResult page(@RequestHeader(value = "belong") String belong, @RequestBody MemberDouyinLifeMemberInfoPageParam param) {
        param.check();
        MemberDouyinLifeMemberInfoPageParamDTO pageParamDTO = param.toDTO();
        pageParamDTO.setBelongEql(belong);
        return ResultUtil.makeResult(douyinLifeMemberInfoService.page(pageParamDTO));
    }

    @PostMapping("/sych")
    public BaseResult sych(@RequestHeader(value = "belong") String belong, @RequestBody DouyinLifeMemberInfoAddParam param) {
        logger.info("接收到抖音本地生活会员同步请求，数据：{}", JSON.toJSONString(param));
        param.check();
        DouyinLifeMemberInfoAddParamDTO addParamDTO = param.toDTO();
        addParamDTO.setBelong(belong);
        douyinLifeMemberInfoService.sych(addParamDTO);
        return new BaseResult(0, "success", null);
    }

    @PostMapping("/remove")
    public BaseResult remove(@RequestHeader(value = "belong") String belong, @RequestBody DouyinLifeMemberInfoDeleteParam param) {

        logger.info("接收到抖音本地生活会员移除请求，数据：{}", JSON.toJSONString(param));

        param.check();
        douyinLifeMemberInfoService.remove(belong, param.getAccountId(), param.getOpenId());
        return new BaseResult(0, "success", null);
    }
}